<script setup>
import { ref, onMounted } from 'vue'
import * as XLSX from 'xlsx'
import axios from "axios";
const nodeVersion = process.versions.node
const upload = ref(null);
const electronVersion = process.versions.electron
const sessionId = ref();
const tbData = ref([])
const apiUrl = ref('')
const tbVo = ref([])
const jsid = ref('')
const ipc = require('electron').ipcRenderer
const getSessionId = () => {
  var c_name = 'JSESSIONID';
  if (document.cookie.length > 0) {
    c_start = document.cookie.indexOf(c_name + "=")
    if (c_start != -1) {
      c_start = c_start + c_name.length + 1
      c_end = document.cookie.indexOf(";", c_start)
      if (c_end == -1) c_end = document.cookie.length
      return unescape(document.cookie.substring(c_start, c_end));
    }
  }
}
onMounted(() => {
  console.log(upload.value)
})
const zuocheng = () => {
  upload.value.clearFiles();
  if (jsid.value == null || jsid.value == '') {
    alert('请填写jsessionId')
    return false
  }
  axios.post('', {}, {
    headers: { Cookie: "JSESSIONID=" + jsid.value }
  })


}
const processFile = (file, fileList) => {
  const reader = new FileReader();
  reader.onload = (e) => {
    try {
      /* 解析数据 */
      const bstr = e.target.result;
      const wb = XLSX.read(bstr, { type: 'binary' });
      /* 获取文件的第一个工作表（WorkSheet） */
      const wsname = wb.SheetNames[0];

      const ws = wb.Sheets[wsname];
      /* 数组转换 */
      const data = XLSX.utils.sheet_to_json(ws, { header: 1 });
      /* 进行表格数据更新 */
      // data.forEach(item=>{
      //   tbData.value.push(item[0])
      // })
      tbData.value = data


      // this.tableData = data;
      /* 进行表格表头数据更新 */
      // this.cols = getHeaderRow(ws);
    } catch (es) {
      this.$message.error('请上传正确的表')
    }


  };
  reader.readAsBinaryString(file.raw);
}

const closeWin = () => {
  ipc.send('closeqinshi')
}


defineProps({
  msg: String
})

const count = ref(0)
</script>

<template>
  <div class="main">
    <el-card style="width: 80%">
      请输入sessionId
      <el-input style="margin-bottom: 20px" v-model="jsid"></el-input>请输入接口Url
      <el-input style="margin-bottom: 20px" v-model="apiUrl"></el-input>
      <el-upload ref="upload" :auto-upload="false" action :on-change="processFile">
        <el-button type="primary">点击上传</el-button>
      </el-upload>
      <el-button type="primary" @click="zuocheng">做成</el-button>
      <!-- <el-button type="primary" @click="closeWin">做成</el-button> -->
      <div v-for="(item) in tbData" :key="item[0]">
        <el-link>{{ item[0] }}</el-link>
      </div>
    </el-card>
  </div>
</template>

<style  scoped>
a {
  color: #42b983;
}

.main {
  display: flex;
  justify-content: space-around;
  align-items: center;
}
</style>
